<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>${msg}</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--公用样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/comment.css">
    <!--页面样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/style.css">
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/extended.css">
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.all.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>

    <style type="text/css">
        /* .layui-form-select .layui-edge{*/
        /*     margin-top: 15px;*/
        /* }*/
        /*.layui-form-select .layui-input {*/
        /*     padding-right: 30px;*/
        /*     cursor: pointer;*/
        /*     width: 75.5%;*/
        /* }*/
        /* .selAddress select {
             float: left !important;
             width: 30% !important;
         }*/
        .layui-form-select dl dd.layui-this {
            background-color: #5775EF;
        }
    </style>

</head>
<body>

<!--头部-->
<header class="whitebg">
    <img src="${re.contextPath}/plugin/common/images/2@2x.png" class="logo" alt=""/>
</header>
<!--容器-->
<div class="container">
    <!--占位-->
    <div class="headerHight"></div>
    <!--注册需方企业账号-->
    <form class="layui-form">
        <div class="regBox regBoxOne whitebg">
            <div class="ft22">${msg}</div>
            <ul class="clearfix">
                <li class="clearfix">
                    <label><span class="red">*</span> 用户名</label>
                    <input type="text" name="username" id="username" value="" lay-verify="username"
                           placeholder="请输入用户名">
                </li>
                <li class="clearfix">
                    <label><span class="red">*</span> 单位名称</label>
                    <input type="text" name="companyName" id="companyName" value="" lay-verify="companyName"
                           placeholder="请输入单位名称">
                </li>
                <li class="clearfix">
                    <nav class="fl">
                        <label><span class="red">*</span> 密码</label>
                        <input type="password" name="password" id="password" value="" lay-verify="password"
                               placeholder="请输入密码">
                    </nav>
                    <div class="gary ft14 fr passTips">密码最少为8位，且至少包含大写字母、小写字母，数字、特殊字符(~!@#$%^&*)中的三种</div>
                </li>
                <li class="clearfix">
                    <label><span class="red">*</span> 联系人</label>
                    <input type="text" name="linkPerson" id="linkPerson" value="" lay-verify="linkPerson"
                           placeholder="请输入联系人">
                </li>
                <li class="clearfix">
                    <label><span class="red">*</span> 联系方式</label>
                    <input type="text" name="phoneNumber" id="phoneNumber" value="" lay-verify="phoneNumber"
                           placeholder="请输入联系方式">
                </li>
                <li>
                    <label>单位性质</label>
                    <div class="layui-col-md9 w80p">
                        <select id=companyType" value="001" name="companyType" lay-verify="companyType">
                            <#list dwlist as vo>
                                <option value="${vo.badtCode}">${vo.badtName}</option>
                            </#list>
                        </select>
                    </div>
                </li>
                <li class="clearfix">
                    <label><span class="red">*</span>邮箱</label>
                    <input type="text" name="email" id="email" value="" lay-verify="email" placeholder="请输入邮箱">
                </li>
                <li class="clearfix">
                    <label><span class="red">*</span> 注册地址</label>
                    <div class="layui-col-md3 w40p">
                        <select name="province" id="province" value="001" style="width: 30% !important;"
                                lay-filter="province" lay-verify="required">
                            <option value="">请选择</option>
                            <#list provincelist as vo>
                                <option value="${vo.code}">${vo.name}</option>
                            </#list>
                        </select>
                    </div>
                    <div class="layui-col-md3 w40p">
                        <select name="city" id="city" class="ml10" value="001" style="width:30% !important;"
                                lay-filter="city" lay-verify="required">
                            <option value="">请选择</option>
                            <#list citylist as vo>
                                <option value="${vo.code}">${vo.name}</option>
                            </#list>
                        </select>
                    </div>
                </li>
                <li class="clearfix">
                    <label>详细地址</label>
                    <input type="text" name="address" id="address" value="" placeholder="请输入详细地址">
                    <input type="hidden" name="gxType" id="gxType" value="${gxType}">
                    <input type="hidden" name="ywType" id="ywType" value="${ywType}">
                    <input type="hidden" name="personType" id="personType" value="${personType}">
                </li>
            </ul>
            <div class="regBtn clearfix">
                <a href="/login" class="fl">返回</a>
                <a href="#" class="fr">
                    <button type="button" lay-filter="register" lay-submit class="bluebg white fr bor0">提交</button>
                </a>

            </div>
            <div class="codePassword agreeLogin center">
                <input type="checkbox" lay-skin="primary" checked id="xychecx" lay-verify="xychecx" class="fl mt10"
                       title="同意"/>
                <span>
						<span><a href="/sys/register/regXy" class="blue">《注册协议》</a></span>和<span><a
                                href="/sys/register/regYs" class="blue">《隐私政策》</a></span>
                </span>
            </div>
        </div>
    </form>
</div>

<!--公用样式JS-->
<script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<!--选择城市js-->
<#--<script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/area.js"></script>-->
<#--<script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/select.js"></script>-->
<script>
    var layer;
    var form = layui.form;
    $(function () {
        layui.use(['form', 'layer'], function () {

            form.verify({
                username: function (v) {
                    if (v.trim() == '') {
                        return "用户名不能为空";
                    }
                }
                , companyName: function (v) {
                    if (v.trim() == '') {
                        return "单位名称不能为空";
                    }
                }, password: function (v) {
                    if(v.trim()==''){
                        return '密码不能为空';
                    }
                    var result = '';
                    $.ajax({
                        url:'/sys/register/checkpwd',
                        data: {pwd: v.trim()},
                        type: 'GET',
                        cache: false,
                        async: false,
                        success: function(res){
                            if(!res.flag){
                                result = '密码格式输入有误';
                            }
                        }
                    })
                    return result;
                }, linkPerson: function (v) {
                    if (v.trim() == '') {
                        return '联系人不能为空';
                    }
                }, phoneNumber: function (v) {
                    if (v.trim() == '') {
                        return '联系方式不能为空';
                    } else {
                        if (!v.trim().isMobile() && !v.trim().isTel()) {
                            return '请输入正确的手机号码或电话号码\n\n例如:13916752109或0531-3614072';
                        }
                    }
                }, companyType: function (v) {
                    if (v.trim() == '') {
                        return '单位性质不能为空';
                    }
                }, email: function (v) {
                    if (v.trim() == '') {
                        return '邮箱不能为空';
                    }else{
                        if (v.trim() != '') {
                            var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                            var flag = reg.test(v.trim());
                            if (!flag) {
                                return '邮箱格式输入有误';
                            }
                        }
                    }
                }
                , province: function (v) {
                    if (v.trim() == '') {
                        return '省不能为空';
                    }
                }, city: function (v) {
                    if (v.trim() == '') {
                        return '市不能为空';
                    }
                }


            });

            /*--------------------选择省获取市-----------------------------------------*/
            form.on('select(province)', function (data) {
                var code = data.value;
                if (code == "") {
                    return;
                }
                layerAjaxGet('/sys/register/getCity', {"code": code}, '', function (d) {
                    if (d.flag == true) {
                        $("#city").empty().append("<option value=''>选择市</option>");
                        for (var i = 0; i < d.data.length; i++) {
                            $("#city").append("<option value='" + d.data[i].code + "'>" + d.data[i].name + "</option>");
                        }
                        form.render('select');
                    } else {
                        layer.msg(d.msg, {icon: 2});
                    }
                });
            });
            //监听提交
            form.on('submit(register)', function (data) {
                var filed = data.field
                if (filed.province != '') {
                    filed.province = filed.province.replace(",", "")
                }
                if (filed.city != '') {
                    filed.city = filed.city.replace(",", "")
                }
                var checked = $("#xychecx").prop('checked');
                if (checked != true) {
                    layer.alert("请勾选同意!");
                    return;
                }
                //供需类型
                if('${gxType}'){
                    filed.gxType = '${gxType}';
                }
                //企业或个人
                if('${personType}'){
                    filed.personType = '${personType}';
                }
                //业务类型
                if('${ywType}'){
                    filed.ywType = '${ywType}';
                }
                // layer.msg(JSON.stringify(data.field));

                layerAjax('/sys/register/register', data.field, '', function (d) {
                    if (d.flag == true) {
                        // 跳转到登录成功页面
                        window.location.href = "/sys/register/retosucess";
                    } else {
                        layer.msg(d.msg, {icon: 2});
                    }
                    console.log(d);
                });
                return false;
            });
            form.render();
        });

        // 电话校验
        String.prototype.Trim = function () {
            var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);
            return (m == null) ? "" : m[1];
        };
        String.prototype.isMobile = function () {
            return (/^1[3|4|5|7|8|9][0-9]\d{4,8}$/.test(this.Trim()));
        };
        String.prototype.isTel = function () {
            //"兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"
            //return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
            return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
        };
        layer = layui.layer;
        var msg = '${message}';
        if (msg.trim() != "") {
            layer.msg(msg, {icon: 5, anim: 6, offset: 't'});
        }
    })


    if (window != top){
        top.location.href = location.href;
    }

</script>


<!-- 底部结束 -->
</body>
</html>
